package com.java28.rbac.service.impl;

import com.java28.rbac.mapper.PermissionMapper;
import com.java28.rbac.pojo.Permission;
import com.java28.rbac.pojo.PermissionExample;
import com.java28.rbac.pojo.PermissionExample.Criteria;
import com.java28.rbac.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired(required=false)
    PermissionMapper permissionMapper;

    @Override
    public List<Permission> findAllParent() {
        PermissionExample permissionExample = new PermissionExample();
        Criteria criteria = permissionExample.createCriteria();
        criteria.andParentidIsNull();
        return permissionMapper.selectByExample(permissionExample);
    }

    @Override
    public List<Permission> findAll(Integer parentId) {
        if (parentId==null){
            parentId=0;
        }
        PermissionExample permissionExample = new PermissionExample();
        Criteria criteria = permissionExample.createCriteria();
        criteria.andParentidEqualTo(parentId);
        return permissionMapper.selectByExample(permissionExample);
    }
}
